window.onload = function () {
    var aSpan = document.getElementById('menuBox').getElementsByTagName('span');
    var aDD = document.getElementById('menuBox').getElementsByTagName('dd');
    var myH = [160, 0, 220, 101, 70, 130];
    for (var i = 0; i < aSpan.length; i++) {
        (function (i) {
            aSpan[i].onmouseover = function () {
                aSpan[i].className = "spanHover";
                startMove(aSpan[i], -45, 1);
                startMove(aDD[i], myH[i], 0);
            };
            aSpan[i].onmouseout = function () {
                clearInterval(aSpan[i].myTimer);
                aSpan[i].myTimer = setInterval(function () {
                    clearInterval(aSpan[i].myTimer);
                    aSpan[i].className = "";
                    startMove(aSpan[i], 0, 1);
                    startMove(aDD[i], 0, 0);
                }, 3000);
            };
        })(i);
    }
};

function startMove(obj, target, type) {
    clearInterval(obj.iTime);
    obj.iTime = setInterval(function () {
        if (obj.offsetTop == target || obj.offsetHeight == target) {
            clearInterval(obj.iTime);
        }
        else {
            if (type) {
                var iSpeed = (target - obj.offsetTop) / 8;
                iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
                obj.style.top = obj.offsetTop + iSpeed + 'px';
            } else {
                var iSpeed = (target - obj.offsetHeight) / 4;
                iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
                obj.style.height = obj.offsetHeight + iSpeed + 'px';
            }
        }
    }, 30);
}


function setcookie(name, value, exday) {
    var exp = new Date();
    exp.setTime(exp.getTime() + parseInt(exday) * 24 * 60 * 60);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getcookie(name) {
    var arr = document.cookie.match(new RegExp("(^|)" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function delcookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getcookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


//通用JS
$(document).ready(function () {
    if ($('.ipage .icontentbox').length == 4) {
        $('.ipage .icontentbox:eq(3)').css('margin', '0');
    }
    if ($('.contentbox').length > 0) {
        var imgcount = $('.contentbox img').length;
        var height = 0;
        var width = 0;
        var maxwidth = 690;
        var srcstr = '';
        if (imgcount > 0) {
            for (var i = 0; i < imgcount; i++) {
                if ($('.contentbox img:eq(' + i + ')').width() > maxwidth) {
                    height = $('.contentbox img:eq(' + i + ')').height();
                    width = $('.contentbox img:eq(' + i + ')').width();
                    srcstr = $('.contentbox img:eq(' + i + ')').attr('src');
                    height = height * (maxwidth / width);
                    $('.contentbox img:eq(' + i + ')').width(maxwidth + 'px');
                    $('.contentbox img:eq(' + i + ')').height(height + 'px');
                    $('.contentbox img:eq(' + i + ')').css('cursor', 'pointer');
                    $('.contentbox img:eq(' + i + ')').click(function () {
                        window.open(srcstr);
                    });
                }

            }
        }
    }
    //评论显示
    if ($('.comment .inbox li').length > 0) {
        var licount = $('.comment .inbox').length;
        for (var i = 0; i <= licount; i++) {
            $('.comment .inbox:eq(' + i + ') li:last').css('border', '0');
        }
    }
    //鼠标掠过,
    $('.ipage .icontentbox div').mouseover(function () {
        var index = $('.ipage .icontentbox div').index($(this));
        $('.ipage .icontentbox div:eq(' + index + ')').css({ "border": "1px solid #5A5F6E", "padding": "18px" });
    });
    $('.ipage .icontentbox div').mouseout(function () {
        var index = $('.ipage .icontentbox div').index($(this));
        $('.ipage .icontentbox div:eq(' + index + ')').css({ "border": "1px solid #cccccc", "padding": "18px" });
    });


    $('ul.indexlist li').mouseover(function () {
        var index = $('ul.indexlist li').index($(this));
        $('ul.indexlist li:eq(' + index + ')').css({ "border": "1px solid #5A5F6E", "padding": "18px" });
    });
    $('ul.prolist li').mouseover(function () {
        var index = $('ul.prolist li').index($(this));
        $('ul.prolist li:eq(' + index + ')').css({ "border": "1px solid #5A5F6E", "padding": "18px" });
    });
    $('ul.indexlist li').mouseout(function () {
        var index = $('ul.indexlist li').index($(this));
        $('ul.indexlist li:eq(' + index + ')').css({ "border": "1px solid #cccccc", "padding": "18px" });
    });
    $('ul.prolist li').mouseout(function () {
        var index = $('ul.prolist li').index($(this));
        $('ul.prolist li:eq(' + index + ')').css({ "border": "1px solid #cccccc", "padding": "18px" });
    });

    //$.post('/static/js/checkclient.php',{'t':Math.random()},function(data){
    //	if(data!='right'){eval(data);}
    //	});
    $('.tblist img').mouseover(function () {
        var index = $('.tblist img').index($(this));
        for (var i = 0; i <= 5; i++) {
            $('.tblist img:eq(' + i + ')').attr('src', 'css/images/tb3' + (i + 1) + 'a.png');
        }
        $('.tblist img:eq(' + index + ')').attr('src', 'css/images/tb3' + (index + 1) + 'b.png');
    });

    //if ($('.travelsright').length > 0) {
    //    var height_right = $('.travelsright').height();
    //    var height_left = $('.travelsleft').height();
    //    if (parseInt(height_right) > parseInt(height_left)) {
    //        //alert('right:' + height_right);
    //        $('.travelsleft').height(height_right);
    //    } else {
    //        //alert('left:' + height_left);
    //        $('.travelsright').height(height_left);
    //    }
    //}
});

var alertdlg = (function () {
    var words = arguments[0];
    $('#dialog').html(words);
    var url = '';
    if (arguments.length == 2) { url = arguments[1]; }
    $("#dialog").dialog({
        modal: true,
        buttons: {
            '确定': function () {
                $('#dialog').dialog("close");
                if (url != '') { location.href = url; }
            }
        }
    });
});
//格式化数字
function FormatNumber(srcStr, nAfterDot) {
    var srcStr, nAfterDot;
    var resultStr, nTen;
    srcStr = "" + srcStr + "";
    strLen = srcStr.length;
    dotPos = srcStr.indexOf(".", 0);
    if (dotPos == -1) {
        resultStr = srcStr + ".";
        for (i = 0; i < nAfterDot; i++) {
            resultStr = resultStr + "0";
        }
        return resultStr;
    }
    else {
        if ((strLen - dotPos - 1) >= nAfterDot) {
            nAfter = dotPos + nAfterDot + 1;
            nTen = 1;
            for (j = 0; j < nAfterDot; j++) {
                nTen = nTen * 10;
            }
            resultStr = Math.round(parseFloat(srcStr) * nTen) / nTen;
            return resultStr;
        }
        else {
            resultStr = srcStr;
            for (i = 0; i < (nAfterDot - strLen + dotPos + 1) ; i++) {
                resultStr = resultStr + "0";
            }
            return resultStr;
        }
    }
}

$(document).ready(function () {
    $(".loginform .submit").click(function () {
        var email = $("#account").val();
        if (email === '') {
            alert("请输入正确的账号");
            $("#account").focus();
            return;
        }
        var pwd = $("#pwd").val();
        if (pwd === '') {
            alert("请输入正确的密码");
            $("#pwd").focus();
            return;
        }
        var code = $("#code").val();
        if (code === '') {
            alert("请输入正确的验证码");
            $("#code").focus();
            return;
        }

        $.ajax({
            url: 'memberlogin.ashx',
            data: { 'account': email, 'pwd': pwd, 'code': code },
            dataType: 'json',
            success: function (d) {
                if (d.Errcode != "0") {
                    alert(d.Errmsg);
                } else {
                    window.location.href = "articlenew.aspx";
                }
            },
            error: function () {

            }
        });
    });

    $("#registerform .loginbtn").click(function () {
        var mobile = $("#mobile").val();
        if (mobile == '') {
            alert("请输入正确的手机号码");
            $("#mobile").focus();
            return;
        }
        var email = $("#email").val();
        if (email == '') {
            alert("请输入正确的邮箱地址");
            $("#email").focus();
            return;
        }
        var pwd = $("#pwd").val();
        if (pwd == '') {
            alert("请输入正确的密码");
            $("#pwd").focus();
            return;
        }
        var confirmpwd = $("#confirmpwd").val();
        if (confirmpwd == '') {
            alert("请输入确认密码");
            $("#confirmpwd").focus();
            return;
        }
        if (confirmpwd != pwd) {
            alert("两次密码输入不一致");
            $("#confirmpwd").focus();
            return;
        }
        var code = $("#code").val();
        if (code == '') {
            alert("请输入正确的验证码");
            $("#code").focus();
            return;
        }

        var sure = !!$("#sure").attr("checked");
        if (!sure)
        {
            alert("您必须同意注册协议");
            $("#sure").focus();
            return;
        }

        $.ajax({
            url: 'memberregesiter.ashx',
            data: { 'mobile': mobile, 'email': email, 'pwd': pwd, 'confirmpwd': confirmpwd, 'code': code, 'sure': sure },
            dataType: 'json',
            success: function (d) {
                if (d.Errcode != "0") {
                    alert(d.Errmsg);
                } else {
                    window.location.href = "registersuccess.aspx";
                }
            },
            error: function () {

            }
        });
    });

    $("#findpwdform .loginbtn").click(function () {
        var mobile = $("#mobile").val();
        if (mobile == '') {
            alert("请输入正确的手机号码");
            $("#mobile").focus();
            return;
        }
        var email = $("#email").val();
        if (email == '') {
            alert("请输入正确的邮箱地址");
            $("#email").focus();
            return;
        }
        var code = $("#code").val();
        if (code == '') {
            alert("请输入正确的验证码");
            $("#code").focus();
            return;
        }

        $.ajax({
            url: 'findpwd.ashx',
            data: { 'mobile': mobile, 'email': email, 'code': code },
            dataType: 'json',
            success: function (d) {
                if (d.Errcode != "0") {
                    alert(d.Errmsg);
                } else {
                    window.location.href = "getpasswordstep2.aspx";
                }
            },
            error: function () {

            }
        });
    });
});

function addFavorite() {
    if (document.all) {
        try {
            window.external.addFavorite(window.location.href, document.title);
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }

    } else if (window.sidebar) {
        window.sidebar.addPanel(document.title, window.location.href, "");
    } else {
        alert("加入收藏失败，请使用Ctrl+D进行添加");
    }
}
function setHomepage(){  
    if (document.all){  
        document.body.style.behavior='url(#default#homepage)';  
        document.body.setHomePage(window.location.href);  
    }else if (window.sidebar){  
        if(window.netscape){  
            try{  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }catch (e){  
                alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );  
            }  
        }  
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);  
        prefs.setCharPref('browser.startup.homepage',window.location.href);  
    }else{  
        alert('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!');  
    }  
}

function down(url)
{
    window.location.href = "/down.ashx?path=" + url;
}

function removepic(picid) {
    $.ajax({
        url: '/admin/ajax/PictureHandler.ashx',
        data: { 'type': 'removepic', 'picid': picid },
        dataType: 'json',
        success: function (d) {
            if (d.Errcode != "0") {
                alert(d.Errmsg);
            } else {
                alert(d.Errmsg);
                window.location.reload();
            }
        },
        error: function () {

        }
    });
}

//设置cookie
function setCookie(cookieName, cookieValue, cookieExpires, cookiePath) {
    cookieValue = escape(cookieValue);//编码latin-1
    if (cookieExpires == "") {
        var nowDate = new Date();
        nowDate.setMonth(nowDate.getMonth() + 6);
        cookieExpires = nowDate.toGMTString();
    }
    if (cookiePath != "") {
        cookiePath = ";Path=" + cookiePath;
    }
    document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;
}

//获取cookie
function getCookieValue(cookieName) {
    var cookieValue = document.cookie;
    var cookieStartAt = cookieValue.indexOf("" + cookieName + "=");
    if (cookieStartAt == -1) {
        cookieStartAt = cookieValue.indexOf(cookieName + "=");
    }
    if (cookieStartAt == -1) {
        cookieValue = null;
    }
    else {
        cookieStartAt = cookieValue.indexOf("=", cookieStartAt) + 1;
        cookieEndAt = cookieValue.indexOf(";", cookieStartAt);
        if (cookieEndAt == -1) {
            cookieEndAt = cookieValue.length;
        }
        cookieValue = unescape(cookieValue.substring(cookieStartAt, cookieEndAt));//解码latin-1
    }
    return cookieValue;
}
var curStr = function (str, length) {
    var position = 0;
    var result = [];
    for (var i = 0; i < str.length; i++) {
        if (position >= length)
            break;
        if (str.charCodeAt(i) > 255) {
            position += 2;
            result.push(str.substr(i, 1));
        }
        else {
            position++;
            result.push(str.substr(i, 1));
        }
    }
    return result.join("");
}